package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.SystemDictionary;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.service.ISystemDictionaryService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import cn.wolfcode.edu.domain.SystemDictionaryItem;
import cn.wolfcode.edu.service.ISystemDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by abb on 2018-07-11.
 */
@Controller
@RequestMapping("systemDictionary")
public class SystemDictionaryController {

    @Autowired
    private ISystemDictionaryService systemDictionaryService;



    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
        JsonResult result = new JsonResult();
        try{
           systemDictionaryService.deleteByPrimaryKey(id);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("有错误");
        }
        return result;
    }

    @RequestMapping("")
    public String index(){
        return "/systemDictionary";
    }



    @RequestMapping("list")
    @ResponseBody
    public List<SystemDictionary> list() {
        return systemDictionaryService.selectAll();
    }

    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(SystemDictionary systemDictionary){
        JsonResult jsonResult = new JsonResult();
        try {
           systemDictionaryService.insert(systemDictionary);

        }catch (Exception e){
            e.printStackTrace();
            jsonResult.setMsg("get wrong");
        }
        return jsonResult;
    }
    //提交保存员工 { success:true,msg:""}
    @RequestMapping("update")
    @ResponseBody

    public JsonResult update(SystemDictionary systemDictionary){
        JsonResult jsonResult = new JsonResult();
        try {
           systemDictionaryService.updateByPrimaryKey(systemDictionary);
        }catch (Exception e){
            e.printStackTrace();
            jsonResult.setMsg("get wrong");
        }
        return jsonResult;
    }

    //根据sn 查询所有子字典  用于给前端的combobox填数据用
    @RequestMapping("getItemBySn")
    @ResponseBody
    public List<SystemDictionaryItem> getItemBySn(String sn){
        List<SystemDictionaryItem> items = systemDictionaryService.getItemBySn(sn);
        return items;
    }


}
